ransomNote = "aa", magazine = "aab"

var canConstruct = function (ransomNote, magazine) {
    for (let str of ransomNote) {
        let index = magazine.indexOf(str)
        if (index === -1) {
            return false;
        } else {
            magazine = magazine.slice(0, index).concat(magazine.slice(index + 1));
        }
    }
    return true;
};

console.log(canConstruct(ransomNote, magazine));
